package com.leetcode.no389;


//给定两个字符串 s 和 t，它们只包含小写字母。
//
//字符串 t 由字符串 s 随机重排，然后在随机位置添加一个字母。
//
//请找出在 t 中被添加的字母。

//输入：s = "abcd", t = "abcde"
//输出："e"
//解释：'e' 是那个被添加的字母。

import java.util.HashMap;

public class Solution {
    public char findTheDifference(String s, String t) {
        HashMap<Character, Integer> sMap = new HashMap<>();
        HashMap<Character, Integer> tMap = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            sMap.putIfAbsent(c, 0);
            sMap.put(c, sMap.get(c) + 1);
        }
        for (int i = 0; i < t.length(); i++) {
            char c = t.charAt(i);
            tMap.putIfAbsent(c, 0);
            tMap.put(c, tMap.get(c) + 1);
        }

        return 0;
    }

    public char findTheDifference01(String s, String t) {
        int as = 0, at = 0;
        for (int i = 0; i < s.length(); i++) {
            as += s.charAt(i);
        }
        for (int i = 0; i < t.length(); i++) {
            at += t.charAt(i);
        }
        return (char) (at - as);
    }

    public char findTheDifference02(String s, String t) {
        int ret = 0;
        for (int i = 0; i < s.length(); i++) {
            ret ^= s.charAt(i);
            System.out.println(ret);
        }
        for (int i = 0; i < t.length(); i++) {
            ret ^= t.charAt(i);
            System.out.println(ret);
        }
        System.out.println(ret);
        return (char) ret;
    }

    public static void main(String[] args) {
        Solution s1 = new Solution();
        char r = s1.findTheDifference02("abcdef", "abcdegf");
        System.out.println("结果是" + r);
    }
}
